package com.mywebsite.core.client;

import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.mywebsite.core.client.gin.MywebGinjector;
import com.mywebsite.core.client.mvp.AppPlaceFactory;
import com.mywebsite.core.client.mvp.AppPlaceHistoryMapper;
import com.mywebsite.core.client.navigation.Navigation;
import com.mywebsite.core.shared.Message;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */

public class Myweb implements EntryPoint {
	
	interface Binder extends UiBinder<HTMLPanel, Myweb> {
	}
	@UiField
	SimplePanel center;
	@UiField(provided=true)
	Navigation navigation;
	public static Message message = GWT.create(Message.class);
	private static Binder binder = GWT.create(Binder.class);
	private MywebGinjector injector = GWT.create(MywebGinjector.class);
	public void onModuleLoad() {
		navigation=new Navigation(injector.getPlaceUtil());
		HTMLPanel outer = binder.createAndBindUi(this);
		RootPanel rp = RootPanel.get();
		rp.add(outer);
		
		EventBus eventBus = injector.getEventBus();
		final PlaceController placeController = injector.getPlaceController(); 
		  
		ActivityMapper activityMapper = injector.getActivityMapper();
		ActivityManager activityManager = new ActivityManager(activityMapper,eventBus);
		activityManager.setDisplay(center);
		  
		AppPlaceFactory factory = injector.getAppPlaceFactory();

		// Start PlaceHistoryHandler with our PlaceHistoryMapper
		AppPlaceHistoryMapper historyMapper = GWT.create(AppPlaceHistoryMapper.class);
		historyMapper.setFactory(factory);
		PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
		historyHandler.register(placeController, eventBus, injector.getPlaceUtil().getDefaultPlace());//此时historyHandler已开始监听placeChangeEvent事件
	
		historyHandler.handleCurrentHistory();
	}
}
